home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: void ** question
- Date: Sun, 24 Mar 96 14:53:28 GMT
- Organization: none
- Message-ID: <827679208snz@genesis.demon.co.uk>
- References: <DoJBrL.F5t@bear.wn.bawue.de> <4iue80$btk@transformer.pti-us.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4iue80$btk@transformer.pti-us.com>
- wv.dixon@pti-us.com "Walt Dixon" writes:
-
- >I am not sure it is legal. void* is an anonymous type,
-
- No, void * is a single type just like long or int *. It is a pointer to
- an incomplete type (since void has no size) so, for example, you can't
- perform pointer arithmetic on it. void isn't the only incomplete type,
- (int []) or (struct foo) where no member list for foo is visible are other
- examples.
-
- The unique property of void * is that you can convert any pointer (except
- pointers to functions) to void * and back again without using a cast (except
- for const/volatile qualifier considerations), and you'll get back a pointer
- that compares equal to the one you started with. The representation of
- void * may be different to other pointers (except char *) so when I say
- 'convert' above a change of representation may really occur (and on some
- systems it does).
-
- >not void**.
-
- void ** is a normal object pointer with no special properties. It can legally
- hold a null pointer or a pointer to a void * object, but that's all.
-
- >Your program should work if you change void f(void**) to void f(void*).
- >It will then be up to you to cast the void* argument to f to the proper type
- >in your case (int**)). Since void* is an anonymous type, the conversion
-
- If the context determines the target type the cast is unnecessary.
-
- >between
- >int** and void* will occur automatically. No casting will be necessary
- >when calling function f.
- >
- >
- >void f(void* x)
- >{
- > int** y = (int**)x;
-
- The cast here is unnecessary.
-
- >}
- >
- >int main(void)
- >{
- > int **ppi;
- > f(ppi)
-
- As it stands this is illegal since it tries to pass the value of an
- uninitialised variable as an argument. You could write something like:
-
- int *pi;
- f(&pi)
-
- > return 0;
- >}
- >
- >
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-